﻿@using System;
@using CoralNode.CoralFile.Entity.Domains;
@using CoralNode.CoralFile.Entity.SearchOrders;
@using CoralNode.CoralFile.Entity.SearchQuerys;
@using Coralcode.Adapter.File.Utils;
@using CoralNode.Core.Entity.Domains.Site;
@using CoralNode.Core.Entity.Enums;
@using Coralcode.Base.Entity.SearchOrders;
@using CoralNode.CoralFile.Entity.Models;
@model Coralcode.Base.Entity.Domains.IPagedDomainList<FileDirectoryModel>
@{
    var query = ViewBag.query as FileStoreSearchQuery;
    var WorkbenchContext = ViewBag.WorkbenchContext as CoralNode.Core.Entity.Domains.Site.SiteDomain;
    IList<DirectoryDomain> treeList = ViewBag.TreeList as List<DirectoryDomain>;
    OrderModel[] orders = ViewBag.orders as OrderModel[];
    ViewData["Module"] = "Node";
    ViewData["curr"] = "file";
}
@Html.IncludePage("CoralAdmin/Node", "_Left")
<div id="pbody">
    <div class="extra">
        <div class="pbody_top">
            <span class="ico ico_setting_file"></span><span class="t t_c">文件管理</span>
        </div>
        <div id="main">
            <div class="filelocal">
                @if (treeList != null && treeList.Count != 0) {
                    for (int i = 0; i < treeList.Count; i++) {
                        if (i == treeList.Count - 1) {
                            <a class="grey" href="/m/file/listfile?query.DirectoryId=@treeList[i].Id">@treeList[i].Title</a>
                        } else {
                            <a class="grey" href="/m/file/listfile?query.DirectoryId=@treeList[i].Id">@treeList[i].Title</a><span class="ico ico_filechild"></span>
                        }
                    }
                }
            </div>
            <div class="tablelist_style1 fileList" data-js="tabellist_style1">
                <div class="funsearch p_1 pl_2 pr_2 extra_normal" data-js="filemanage" data-delhref="#"
                     data-savehref="#">
                    <div class="filefun f_l">
                        <a class="btn btn_file_upload mr_1 js_openuploader" data-meta="{data:'{parentId:\'@(treeList == null ? 0 : treeList.Last().Id)\',module:\'FileManage\'}',multi:true,method:'add',type:'file',okfun:'fileUploadOk'}">
                        </a>
                        <a class="btn btn_file_newdic mr_1" href="/m/file/CreateDir?parentId=@(treeList == null ? 0 : treeList.Last().Id)">
                        </a>
                        <!-- 下载连接 参数另传 -->
                        <a class="btn btn_file_download" href="download.html"></a>
                        <a class="btn btn_file_rename" href="/m/file/RenameFile"></a>
                        <a class="btn btn_file_delmul" href="/m/file/deletemultifile"></a>
                    </div>
                    <div class="f_r">
                        <form method="get" action="">
                            <span class="t_des f_l pt_0-5">文件名称：</span>
                            <label class="search f_l">
                                <input class="text w_18" name="query.Title" value="@query.Title" /><input type="submit"
                                                                                                          value="" class="submit" />
                            </label>
                        </form>
                    </div>
                </div>
                <div class="filesort">
                    <div class="sortcontent">
                        <div class="sort f_l js_fileSearch" data-meta="{'param':'Type'}">
                            <span>分类显示：</span><a class="btn btn_filesort_all" href="0"></a><a class="btn btn_filesort_image"
                                                                                              href="1" title="图片"></a><a class="btn btn_filesort_doc" href="2"
                                                                                                                         title="文档"></a><a class="btn btn_filesort_music" title="音频" href="4"></a><a class="btn btn_filesort_film"
                                                                                                                                                                                                     href="5" title="视频"></a>
                        </div>
                        <div class="order f_r mr_2">
                            <span>时间：</span><a class="ico ico_movedown"></a>
                            @*<a class="ico ico_moveup"></a>*@
                        </div>
                    </div>
                </div>
                <table cellpadding="0" cellspacing="0">
                    <tr class="exclude">
                        <th width="60">选择</th>
                        <th align="left">文件名</th>
                        <th width="100">大小</th>
                        <th width="120">类型</th>
                        <th width="100">修改日期</th>
                        <th width="140">操作</th>
                    </tr>
                    @foreach (var item in Model.Items) {
                        <tr data-type="@(item.Directory == null ? "file" : "directory")">
                            <td>
                                <label class="checkbox_own">
                                    <input type="checkbox" value="@(item.Directory == null ? item.FileStore.Id : item.Directory.Id)" />
                                </label>
                            </td>
                            <td class="td_left">
                                <span class="ico" data-file="@(item.Directory == null ? item.FileStore.Path : "/")">
                                </span>
                                <a href="@(item.Directory != null ? "/m/file/listfile?query.DirectoryId=" + item.Directory.Id : "javascript:void(0)")">@(item.Directory != null ? item.Directory.Title : item.FileStore.Title)</a><input type="text" class="w_20 text f_no" value="" /><div class="fun_m">
                                    <a class="btn btn_file_edit" href="save.html?id=3"></a><a class="btn btn_file_del"
                                                                                              href="delete.html?id=3"></a>
                                </div>
                            </td>
                            <td>
                                @(item.Directory != null ? string.Empty : FileUtil.FormatSize(Convert.ToInt32(item.FileStore.Size)))
                        </td>
                        <td>
                            @(item.Directory != null ? "文件夹" : item.FileStore.Extension.Substring(item.FileStore.Extension.IndexOf('.') + 1))
                    </td>
                    <td>
                        @(item.Directory != null ? item.Directory.CreateTime.ToString("yyyy-MM-dd") : item.FileStore.UpdateTime.ToString("yyyy-MM-dd"))
                </td>
                <td>
                    <div class="fun">
                        @if (item.Directory == null) {
                            string shareHref = Request.Url.Host + (Request.Url.Port == 80 ? string.Empty : (":" + Request.Url.Port.ToString())) + item.FileStore.Path;
                            <a href="@item.FileStore.Path" target="_blank">下载</a>
                            <a href="javascript:void(0)" class="js_zclip" data-meta="{msg:'@shareHref',tip:'文件链接已经复制到剪切板！'}">
                                分享
                            </a>
                        } else {
                            <a href="#" target="_blank">下载</a>
                            <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
                        }
                        <a href="/m/file/deletefile?id=@(item.Directory != null ? (item.Directory.Id + "&type=directory") : (item.FileStore.Id + "&type=file"))" class="js_operate">
                            删除
                        </a>
                    </div>
                </td>
            </tr>
                    }


                </table>
                <div class="global_fun ">
                    <label class="checkbox_own gloabal_select">
                        <input type="checkbox" />
                    </label>
                    <input type="button" class="btn_4 btn invert" value="反选" /><input type="button" class="btn_4 btn reset"
                                                                                      value="重置" />
                </div>
            </div>

        </div>
        @Html.IncludePage("CoralAdmin/Shared", "Pager2", new { list = Model })
    </div>
</div>
<div id="fileTitle" style="display: none;">
    <div class="cnt">
        <span>鹏元香港官网</span> > <span>关于我们</span> > <span>资质资历</span>
        <a href="http://www.pyratting.hk/aboutus_certificate.html">http://www.pyratting.hk/aboutus_certificate.html</a>
    </div>
    <span class="ico ico_filelink_down"></span>
</div>

<script>

    $(function () {
        getUrlEncodedKey = function (key, query) {
            if (!query)
                query = window.location.search;
            var re = new RegExp("[?|&]" + key + "=(.*?)&");
            var matches = re.exec(query + "&");
            if (!matches || matches.length < 2)
                return "";
            return decodeURIComponent(matches[1].replace("+", " "));
        }
        setUrlEncodedKey = function (key, value, query) {

            query = query || window.location.search;
            var q = query + "&";
            var re = new RegExp("[?|&]" + key + "=.*?&");
            if (!re.test(q))
                q += key + "=" + encodeURI(value);
            else
                q = q.replace(re, "&" + key + "=" + encodeURIComponent(value) + "&");
            q = q.trimStart("&").trimEnd("&");
            return q[0] == "?" ? q : q = "?" + q;
        }
        $(".js_fileSearch").find("a,input[type='submit']").click(function (e) {
            e.preventDefault();
            var $this = $(this);
            var value = $this.attr("href");
            value = value == "" || value == null || value == undefined ? $this.prev("input[type='text']").val() : value;
            var param = $this.parents(".js_fileSearch").metadata().param;
            location.href = setUrlEncodedKey("query." + param, $this.attr("href"));
        })
    })
    function fileUploadOk(files) {
        if (files.length > 0) {
            var dataStr = '';
            for (var i = 0; i < files.length; i++) {
                dataStr += "files[" + i + "].Title=" + files[i].title + "&";
                dataStr += "files[" + i + "].FilePath=" + files[i].filePath + "&";
                dataStr += "files[" + i + "].Description=" + files[i].description;
                if (i = files.length - 1)
                    dataStr += "&"
            }
            $.post("/m/file/createfile?parentId=@(treeList == null ? 0 : treeList.Last().Id)", dataStr, function (data) {
                if (data) {
                    location.reload();
                }
                else {
                    $.alert("上传失败！", "error");
                }
            });
        }
    }
</script>

